//
//  ChartHelper.m
//  GlobalAutoBusiness
//
//  Created by dongzhenyu on 2017/2/8.
//  Copyright © 2017年 dongzhenyu. All rights reserved.
//

#import "ChartHelper.h"
#import "UIColor+hexadecimal.h"


#define kRed [UIColor colorWithHexadecimalStr:@"f5605e"]
#define kLightBlue [UIColor colorWithHexadecimalStr:@"70bfff"]
#define kYellow [UIColor colorWithHexadecimalStr:@"ffe26c"]
#define kDarkBlue [UIColor colorWithHexadecimalStr:@"1983d1"]

#define WIDTH_SCALE ([UIScreen mainScreen].bounds.size.width)/375.0
#define HEIGHT_SCALE ([UIScreen mainScreen].bounds.size.height)/667.0

@implementation ChartHelper

- (instancetype)initWithFrame:(CGRect)rect type:(int)type
{
    self.barChart = [[PNBarChart alloc] initWithFrame:rect type:type];
    
    self.barChart.barWidth = rect.size.width/(type == 1 ? 7 : 5)-20*WIDTH_SCALE;
    self.barChart.yChartLabelWidth = 30.0*WIDTH_SCALE;
    self.barChart.chartMarginLeft = 30.0*WIDTH_SCALE;
    self.barChart.chartMarginRight = 10.0*WIDTH_SCALE;
    self.barChart.chartMarginTop = 5.0*HEIGHT_SCALE;
    self.barChart.chartMarginBottom = 10.0*HEIGHT_SCALE;
    self.barChart.labelFont = [UIFont systemFontOfSize:10*WIDTH_SCALE];
    self.barChart.labelTextColor = [UIColor colorWithHexadecimalStr:@"666666"];
    self.barChart.barBackgroundColor = [UIColor whiteColor];
    
    self.barChart.labelMarginTop = 5.0;
    self.barChart.showChartBorder = YES;
    
    if (type == 1) {
        [self.barChart setXLabels:@[@"到店养护", @"美容", @"洗车", @"闪付", @"到店保养4s", @"钣喷", @"配件"]];
        [self.barChart setYValues:@[@0, @0, @0, @0, @0, @0, @0]];
        [self.barChart setStrokeColors:@[kRed, kLightBlue, kYellow, kDarkBlue, kYellow, kRed, kLightBlue]];
    } else {
        [self.barChart setXLabels:@[@"到店养护", @"美容", @"洗车", @"闪付", @"钣喷", @"配件"]];
        [self.barChart setYValues:@[@0, @0, @0, @0, @0, @0]];
        [self.barChart setStrokeColors:@[kRed, kLightBlue, kYellow, kDarkBlue, kRed, kLightBlue]];
    }
    
    self.barChart.isGradientShow = NO;
    self.barChart.isShowNumbers = YES;
    
    [self.barChart strokeChart];
    return self;
}

- (void)updateData:(NSArray *)data
{
//    self.barChart setValue:data.count++ forKey:<#(nonnull NSString *)#>
    [self.barChart updateChartData:data];
}


@end
